package com.components.cachewebview

import android.text.TextUtils
import okhttp3.Interceptor
import okhttp3.Response

class HttpCacheInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val cache = request.header(WebViewCacheInterceptor.KEY_CACHE)
        val originResponse = chain.proceed(request)
        if (!TextUtils.isEmpty(cache) && cache.equals(CacheType.NORMAL.ordinal.toString())) {
            return originResponse
        }
        return originResponse.newBuilder().removeHeader("pragma").removeHeader("Cache-Control")
            .header("Cache-Control", "max-age=3153600000").build()
    }
}